﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Reflection;

namespace JustPlus
{
    /// <summary>
    /// MVWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MVWindow : Window
    {
        public MVWindow()
        {
            InitializeComponent();
            if (!string.IsNullOrEmpty(SearchPanel.mvurl))
            {
                webBrowser1.Navigate(new Uri(SearchPanel.mvurl, UriKind.RelativeOrAbsolute));
                WebBrowserExtensions.SuppressScriptErrors(webBrowser1, true);
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            webBrowser1.Dispose();
        }
    }

    public static class WebBrowserExtensions
    {
        public static void SuppressScriptErrors(this WebBrowser webBrowser, bool hide)
        {
            FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fiComWebBrowser == null) return;

            object objComWebBrowser = fiComWebBrowser.GetValue(webBrowser);
            if (objComWebBrowser == null) return;

            objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });
        }
    }
}
